package gates;

import mathtools.Complex;
import mathtools.Matrix;
import register.Register;

/**
 * Nand all inputs: This matrix flips all states except the first state. 
 * Surrounded by two hadamard transforms makes the inversion about mean.
 * Flips all states in vector space orthogonal to vector space of first state. 
 * @author Jan Zaucha, Alex Bush
 *
 */
public class NandAllMatrix extends MatrixGate {


	/**
	 * Protected constructor to create an instance of this object
	 * 
	 */
	protected NandAllMatrix(){
	}
	

	/**
	 * Matrix that will flip all states except 0 state
	 *
	 * @param r the register 
	 */
	public void apply(Register r) {
		int numStates = r.getNumStates();
		Matrix nand = Matrix.IdentityMatrix(numStates);
		for (int i=1; i<numStates; i++){
			nand.setElement(i, i, new Complex(-1));
		}
		r.update(nand.multiplyMatrix(r));
	}	

	/**
	 * Returns the name of the gate regardless of representation.
	 */
	public String getName() {
		return "Nand All";
	}

}
